package com.springboot2.service.Impl;

import com.springboot2.entity.Information;
import com.springboot2.mapper.InformationMapper;
import com.springboot2.service.InformationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class InformationSeriveImpl implements InformationService {

    @Resource
    private InformationMapper informationMapper;

    @Override
    public void add(Information information) {
        informationMapper.add(information);
    }

    @Override
    public void del(int id) {
        informationMapper.del(id);
    }

    @Override
    public void update(Information information) {
        informationMapper.update(information);
    }

    @Override
    public Information findById(int id) {
        return informationMapper.findById(id);
    }

    @Override
    public List<Information> findByPage(int pageNo, int pageSize) {
        Map<String,Integer> map = new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);

        return informationMapper.findByPage(map);
    }

    @Override
    public int count() {
        return informationMapper.count();
    }

    @Override
    public List<Information> findByPageParams(int pageNo, int pageSize, String title) {
        Map<String,Object> map = new HashMap<>();
        map.put("pageNo",(pageNo-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("title",title+"%");
        return informationMapper.findByPageParams(map);
    }

    @Override
    public int countParams(String title) {
        return informationMapper.countParams(title);
    }
}
